/**
 *
 * @Author: Marek Zakowicz <mazak (at) debian (dot) linux.org.pl>
 *
 * Copyright (c) 2005, 2006, 2007 Marek Zakowicz. All rights reserved.
 *
 * Licence: This code may be used, (re)distribute and/or modify under the terms one of the following two kinds of licence:
 *          1) as free software under GPL 3 (General Public Licence ver. 3 as published by the Free Software Foundation)
 *          2) as software under the terms individual licence from Marek Zakowicz
 *
 *          This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *          without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */

package jsp2php;

class StaticDoubleClassTranslator extends TranslatorBase {

   StaticDoubleClassTranslator() {
      fields.put("MAX_VALUE", DoubleValueTranslator.literal(Double.MAX_VALUE) );
      fields.put("MIN_VALUE", DoubleValueTranslator.literal(Double.MIN_VALUE) );
      fields.put("NaN", new Translation("NAN", JavaType._double(), true, true) );
      fields.put("POSITIVE_INFINITY", new Translation("INF", JavaType._double(), true, true) );
      fields.put("NEGATIVE_INFINITY", new Translation("-INF", JavaType._double(), true, true) );
      fields.put("SIZE", IntValueTranslator.literal(64) );
   }

   public String name() {
      return "java.lang.Double";
   }

   // TRANSLATOR
   //public Translation translate_compare(Translation ... args) throws TranslatorException {

   public Translation translate_isInfinite(Translation ... args) throws TranslatorException {
      return static_translate("isInfinite", "is_infinite(%s)", JavaType._double(), JavaType.bool(), args);
   }

   public Translation translate_isNaN(Translation ... args) throws TranslatorException {
      return static_translate("isNaN", "is_nan(%s)", JavaType._double(), JavaType.bool(), args);
   }

   public Translation translate_parseDouble(Translation ... args) throws TranslatorException {
      validate_arg_no(1, "parseDouble", args);
      validate_arg_type(JavaType.string(), "parseDouble", args);

      Translation arg = args[1];
      if(arg.consistent) {
         return new Translation(String.format("(float) %s", arg.text), JavaType._double(), true, arg.not_null);
      }
      else {
         return new Translation(String.format("(float) (%s)", arg.text), JavaType._double(), true, arg.not_null);
      }
   }

   public Translation translate_toString(Translation ... args) throws TranslatorException {
      validate_arg_no(1, "toString", args);
      validate_arg_type(JavaType._double(), "toString", args);

      Translation arg = args[1];
      if(arg.consistent) {
         return new Translation(String.format("(string) %s", arg.text), JavaType.string(), true, arg.not_null);
      }
      else {
         return new Translation(String.format("(string) (%s)", arg.text), JavaType.string(), true, arg.not_null);
      }
   }

}


/**
 * @composed 1 - 1 DoubleClassValueTranslator
 */
class DoubleClassTranslator extends StaticDoubleClassTranslator implements ITypeTranslator {
   private static IValueTranslator value_translator = new DoubleClassValueTranslator();

   static {
      ITypeTranslator tr = new DoubleClassTranslator();
      JavaType.add_type_translator( tr );
   }

   private DoubleClassTranslator() {}

   public IValueTranslator value_translator() {
      return value_translator;
   }
}

class DoubleClassValueTranslator extends StaticDoubleClassTranslator implements IValueTranslator {
   // TODO: (Un-)boxing przez delegacje do double
}
